package com.pipe.servicepipe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pipe.commonutils.R;
import com.pipe.servicepipe.annotation.OperationAnnotation;
import com.pipe.servicepipe.entity.PipeDebt;
import com.pipe.servicepipe.entity.vo.PipeDebtQuery;
import com.pipe.servicepipe.service.PipeDebtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 欠款记录表 前端控制器
 * </p>
 *
 * @author hetao
 * @since 2020-07-12
 */
@RestController
@RequestMapping("/debt")
@Api(tags = "PipeDebtController", description = "欠款管理")
public class PipeDebtController {
    @Resource
    private PipeDebtService pipeDebtService;

    @GetMapping
    @ApiOperation("欠款查询")
    @OperationAnnotation("查询了欠款记录")
    public R queryDebtByPage(@ApiParam(required = false,value = "查询条件")
                                 @RequestBody PipeDebtQuery pipeDebtQuery,
                             @ApiParam(required = false,value = "当前页码")
                                 @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                             @ApiParam(required = false,value = "每页显示行数")
                                 @RequestParam(required = false, defaultValue = "20") Integer pageSize){
        Page<PipeDebt> page = new Page<PipeDebt>(pageNum,pageSize);
        this.pipeDebtService.findByPage(page,pipeDebtQuery);
        return R.ok();
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除欠款记录")
    @OperationAnnotation("删除了欠款记录")
    public R deleteDebtById(@PathVariable("id") String id) {
        this.pipeDebtService.removeById(id);
        return R.ok();
    }

    @PostMapping
    @ApiOperation("新增欠款记录")
    @OperationAnnotation("新增了欠款记录")
    public R saveDebt(@RequestBody PipeDebt debt) {
        this.pipeDebtService.save(debt);
        return R.ok().message("添加成功");
    }


    //hetao_todo 导出pdf


}

